package com.cqeec.demo01.controller;

import com.cqeec.demo01.entity.Dish;
import com.cqeec.demo01.service.DishService;
import com.cqeec.demo01.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @RequestMapping("/list/{current}")
    public String list(@PathVariable int current, Model model) {
        // 调用dishService的list方法，传入当前页码，获取分页后的菜品列表
        Page<Dish> page = dishService.list(current);

        // 将获取到的分页对象添加到Model中，键名为“page”
        model.addAttribute("page", page);

        // 返回视图名称“dish/index”，该视图将用于展示菜品列表
        return "dish/index";
    }
}
